<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/6
 * Time: 16:31
 */
namespace  Admin\Controller;
use Admin\Model\InspectionContentModel;
use Admin\Model\InspectiondetailinfoModel;
use Admin\Model\InspectionPicDetailModel;
use Base\Controller\CurdController;

class InspectionIndexController extends  CurdController {

    public function __construct()
    {
        parent::__construct(true, true);

    }
    protected function getAll()
    {
        if(I('get.userid')){
            $where['userid']=I('get.userid');
        }
        if(I('get.hospitalid')){
            $where['hospitalid']=I('get.hospitalid');
        }
        if($_REQUEST['selects']){
            $limit=$_REQUEST['selects'];
        }else{
            $limit=20;
        }
        $where['status']=array('EGT','0');
        $data = $this->model->pageToView($limit, true,$where);
//       dump($data);
        $this->assign("page", $data['page']);
        $this->assign("list", $data['list']);
    }
    /**
     * 编辑界面
     * @param $id
     */
    public function showEdit($id)
    {
        if (!$id) {
            $this->error('非法操作');
        }
        $select = $this->model->find($id);
        $InspectionContentModel=new InspectionContentModel();
        $groupid=$InspectionContentModel->where(array('indexid'=>$select['id']))->group('testid')->select();
//        echo $InspectionContentModel->_sql();
//       dump($groupid);
        if (empty($select)) {
            $this->error('非法操作');
        }
        $this->assign('groupid',$groupid);
        $this->assign('data', $select);
        $this->show('');
    }

    /**
     * 获取检查单子项
     */
    public  function getiteminfolist(){
        $where['indexid']=$_REQUEST['indexid'];
        $where['testid']=$_REQUEST['testid'];
        $InspectionContentModel=new InspectionContentModel();
        $list=$InspectionContentModel->relation(true)->where($where)->select();

        $this->ajaxReturn($list);
    }
    public  function getimgs(){
        $wheres['indexid']=$_REQUEST['indexid'];
        $wheres['itemid']=$_REQUEST['testid'];
        $InspectionPicDetailModel=new InspectionPicDetailModel();
        $pic= $InspectionPicDetailModel->where($wheres)->select();
//        echo $InspectionPicDetailModel->_sql();
        $this->ajaxReturn($pic);
    }
}